from wordcloud import WordCloud
import matplotlib.pyplot as plt
import pandas as pd
# 读取包含需要保留列的 CSV 文件
df = pd.read_csv("modified_csv_file.csv")
import pandas as pd
# Cluster centers:
# Cluster 0: [1.91472868 3.53488372 1.41085271 2.28682171 1.82945736]
# Cluster 1: [3.5503876  2.71317829 4.78294574 3.13953488 1.81395349]
# Cluster 2: [3.94573643 2.28682171 9.70542636 3.07751938 2.17829457]
# 将数据集按照聚类标签分组
grouped = df.groupby('tKMeans_Label')
plt.rcParams['font.family'] = 'SimHei'
# 定义特征列列表
feature_columns = ['Q2', 'Q3', 'Q4', 'Q5', 'Q6', 'Q10', 'Q11', 'Q12', 'Q13', 'Q14']

# 遍历每个聚类组
for group_label, group_data in grouped:
    print(f"Cluster {group_label}:")

    # 遍历每个特征列
    for col in feature_columns:
        feature_counts = group_data[col].value_counts()
        print(f"Feature: {col}")
        print(feature_counts)
        print()

    print()
# 计算每个聚类中的聚类中心
cluster_centers = grouped.mean()
print(cluster_centers)
import pandas as pd

# 读取包含 KMeans 标签的文件
df_with_labels = pd.read_csv("new_file_with_kmeans_labels.csv")

# 计算每种聚类分类的数量
cluster_counts = df_with_labels['tKMeans_Label'].value_counts()

# 计算每种聚类分类的占比
cluster_proportions = cluster_counts / len(df_with_labels)

print(cluster_proportions)
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# 读取包含 KMeans 标签的文件
df_with_labels = pd.read_csv("new_file_with_kmeans_labels.csv")

# 计算每个聚类中的样本数
cluster_counts = df_with_labels['tKMeans_Label'].value_counts()

# 计算每个聚类的样本占总样本数量的比例
cluster_percentage = cluster_counts / len(df_with_labels) * 100

# 打印出每个聚类的样本数量和占比
print("聚类样本数量和占比:")
print(cluster_counts)
print(cluster_percentage)

# 使用柱状图可视化
plt.figure(figsize=(10, 6))
sns.barplot(x=cluster_counts.index, y=cluster_counts.values, palette='viridis')
plt.title('每个聚类中的样本数量')
plt.xlabel('聚类标签')
plt.ylabel('样本数量')
plt.show()

plt.figure(figsize=(10, 6))
sns.barplot(x=cluster_percentage.index, y=cluster_percentage.values, palette='viridis')
plt.title('每个聚类中的样本占比')
plt.xlabel('聚类标签')
plt.ylabel('样本占比 (%)')
plt.show()
